require(["config"], function(config) {
	require(["jquery", "sw", "cook", "cooki", "one"], function(jquery, sw, cook, cooki, one) {
		$(function() {

			/*$('.input input').focus(function() {
				$('.id_icon').css("display", "none")
				$('.password_icon').css("display", "none")

			})

			$('.input input').blur(function() {
				if ($(this).siblings().hasClass('id_icon')) {

					$(this).siblings().removeClass('id_icon_focus')
				} else {
					$(this).siblings().removeClass('password_icon_focus')
				}
			})
*/
			$(".submit").click(function() {

				if ($('input[name=user]').val() == '') {
					//$('.remind_error').show(400);
					$('.id_icon').css({
						"display": "block",
						"color": "red"
					}).html('请输入用户名');
					return false
					if ($('input[name=password]').val() == '') {
						//$('.remind_error').show(400);
						$('.password_icon').css({
							"display": "block",
							"color": "red"
						}).html('请输入密码');
						return false
					}
				} else if ($('input[name=user]').val() == '' && $('input[name=password]').val() == '') {
					$('.password_icon').css({
						"display": "block",
						"color": "red"
					}).html('请输入密码');
					$('.id_icon').css({
						"display": "block",
						"color": "red"
					}).html('请输入用户名');

				}
			})

			//获取页面元素
			var yonghu = document.getElementById("yonghu")
			var mima = document.getElementById("mima")
			var deng = document.getElementById("deng")
				//给登录按钮加点击事件
			deng.onclick = function() {
				//获取用户输入的用户名和密码
				var usn = yonghu.value;
				var pwd = mima.value;

				//校验用户名和密码是否正确
				//获取到cookie中的用户信息
				var users = getCookie("test") ? getCookie("test") : "";
				//将字符串转为对象
				users = convertStrToObj(users);

				if (users[usn] == pwd) {
					//登录成功
					//			setCookie("test",usn,7);
					alert("登录成功!");
					location.href = "index.html";
				} else {
					//登录失败
					$('.password_icon').css({
						"display": "block",
						"color": "red"
					}).html('用户名和密码不匹配，请确认后重试！');
					//alert("用户名和密码不匹配，请确认后重试！");
				}
			};

			//将字符串转为对象
			function convertStrToObj(str) {
				if (!str) { //如果是空字符串
					return {}; //返回空对象
				}
				var users = str.split(":");
				var obj = {};
				for (var i = 0; i < users.length; i++) {
					var userData = users[i].split(",");
					obj[userData[0]] = userData[1];
				}
				return obj;
			}

			//将对象转为字符串
			
			function convertObjToStr(obj){
				var str = "";
				//遍历对象
				for (var usn in obj) {
					var pwd = obj[usn];
					if (str) {
						str += ":";
					}
					str += usn + ',' + pwd;
					console.log(str)
				}
				return str;
			}

		})

	})

})